package edu.chinasoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.annotation.WebServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import edu.chinasoft.domain.Function;
import edu.chinasoft.service.FunctionService;

/**
 *
 * @author mhao
 * @date 2020年2月12日:下午3:56:48
 * @version V1.0
 * @Description: 
*/
@WebServlet(name = "myUpdateFunctionPageServlet", value = "/servlet/updatefunctionpageservlet")
public class UpdateFunctionPageServlet extends HttpServlet {
	private static Logger logger = LoggerFactory.getLogger(UpdateFunctionPageServlet.class);
	private FunctionService functionService;
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" UpdateFunctionPageServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		FunctionService functionServiceImp = wac.getBean("functionService", FunctionService.class);
		this.functionService=functionServiceImp;
		//获取当前权限的id
		String num = request.getParameter("id");
		int id = Integer.parseInt(num);
		logger.info("当前权限的id："+id);
		Function function = new Function();
		function.setFunctionId(id);
		//通过id获取当前权限的其他信息
		Function selectFunctionById = functionService.selectFunctionById(function);
		logger.info("当前权限为："+selectFunctionById+":"+selectFunctionById.getFatherFunction());
		//获取所有父亲权限信息
		List<Function> functionList = functionService.selectFatherFunction();
		HttpSession session = request.getSession();
		session.setAttribute("updateFunction", selectFunctionById);
		session.setAttribute("allFatherFunction", functionList);
		response.sendRedirect(""+request.getContextPath()+"/updatefunction.jsp");
		logger.info(" UpdateFunctionPageServlet >doGet end.......");
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" UpdateFunctionPageServlet >doPost start.......");
		this.doGet(request, response);
		logger.info(" UpdateFunctionPageServlet >doPost end.......");
	}

}